﻿using DocumentFormat.OpenXml.Lite.DrawingML.Types;
using DocumentFormat.OpenXml.Lite.Shared;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.DrawingML.Text
{
    [XmlRoot("tabLst", Namespace = Constants.Main)]
    public class TabList : XmlSerializable
    {
        [Optional]
        [XmlElement("tab", Namespace = Constants.Main)]
        public XmlList<Tab> Tabs { get; set; }

        public TabList()
        {
            Tabs = new XmlList<Tab>();
            Tabs.Changing += Tabs_Changing;
        }

        void Tabs_Changing(object sender, ListEventArgs<Tab> args)
        {
            if (Tabs.Count == 32)
            {
                args.Canceled = true;
            }
        }
    }

    [XmlRoot("tab", Namespace = Constants.Main)]
    public class Tab : XmlSerializable
    {
        [Optional]
        [XmlAttribute("pos", Form = XmlSchemaForm.Qualified)]
        public Nullable<int> Position { get; set; }

        [Optional]
        [XmlAttribute("algn", Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_TextTabAlignType> Alignment { get; set; }

        public Tab() { }
    }
}
